package cn.edu.suda.ada.common.config;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import cn.edu.suda.ada.database.connection.DbProperties;
import cn.edu.suda.ada.database.exception.DatabaseException;

public class PropertiesConfig extends DefaultConfig {
	private Properties properties;
	
	protected PropertiesConfig(String path) throws DatabaseException {
		properties = new Properties();
		InputStream is = DbProperties.class.getResourceAsStream(path);
		try {
			if (null != is) {
				logger.info("成功加载配置文件：{}", path);
				properties.load(is);
			}
			else throw new DatabaseException("配置文件不存在：" + path);
		} catch (IOException e) {
			throw new DatabaseException("无法加载配置文件：" + path, e);
		}
	}
	
	@Override
	public String getString(String key) {
		return properties.getProperty(key);
	}
}
